// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso;

import java.io.IOException;
import java.nio.ByteBuffer;
import zombie.core.Core;
import zombie.core.textures.ColorInfo;
import zombie.iso.sprite.IsoDirectionFrame;
import zombie.iso.sprite.IsoSprite;
import zombie.iso.sprite.IsoSpriteManager;

public final class IsoWallBloodSplat {
    private static final ColorInfo info = new ColorInfo();
    public float worldAge;
    public IsoSprite sprite;

    public IsoWallBloodSplat() {
    }

    public IsoWallBloodSplat(float _worldAge, IsoSprite _sprite) {
        this.worldAge = _worldAge;
        this.sprite = _sprite;
    }

    public void render(float x, float y, float z, ColorInfo objectColor) {
        if (this.sprite != null) {
            if (this.sprite.CurrentAnim != null && !this.sprite.CurrentAnim.Frames.isEmpty()) {
                int int0 = Core.TileScale;
                int int1 = 32 * int0;
                int int2 = 96 * int0;
                if (IsoSprite.globalOffsetX == -1.0F) {
                    IsoSprite.globalOffsetX = -IsoCamera.frameState.OffX;
                    IsoSprite.globalOffsetY = -IsoCamera.frameState.OffY;
                }

                float float0 = IsoUtils.XToScreen(x, y, z, 0);
                float float1 = IsoUtils.YToScreen(x, y, z, 0);
                float0 -= (float)int1;
                float1 -= (float)int2;
                float0 += IsoSprite.globalOffsetX;
                float1 += IsoSprite.globalOffsetY;
                if (!(float0 >= (float)IsoCamera.frameState.OffscreenWidth) && !(float0 + (float)(64 * int0) <= 0.0F)) {
                    if (!(float1 >= (float)IsoCamera.frameState.OffscreenHeight) && !(float1 + (float)(128 * int0) <= 0.0F)) {
                        info.r = 0.7F * objectColor.r;
                        info.g = 0.9F * objectColor.g;
                        info.b = 0.9F * objectColor.b;
                        info.a = 0.4F;
                        float float2 = (float)zombie.GameTime.getInstance().getWorldAgeHours();
                        float float3 = float2 - this.worldAge;
                        if (float3 >= 0.0F && float3 < 72.0F) {
                            float float4 = 1.0F - float3 / 72.0F;
                            info.r *= 0.2F + float4 * 0.8F;
                            info.g *= 0.2F + float4 * 0.8F;
                            info.b *= 0.2F + float4 * 0.8F;
                            info.a *= 0.25F + float4 * 0.75F;
                        } else {
                            info.r *= 0.2F;
                            info.g *= 0.2F;
                            info.b *= 0.2F;
                            info.a *= 0.25F;
                        }

                        info.a = Math.max(info.a, 0.15F);
                        ((IsoDirectionFrame)this.sprite.CurrentAnim.Frames.get(0)).render(float0, float1, IsoDirections.N, info, false, null);
                    }
                }
            }
        }
    }

    public void save(ByteBuffer output) {
        output.putFloat(this.worldAge);
        output.putInt(this.sprite.ID);
    }

    public void load(ByteBuffer input, int WorldVersion) throws IOException {
        this.worldAge = input.getFloat();
        int _int = input.getInt();
        this.sprite = IsoSprite.getSprite(IsoSpriteManager.instance, _int);
    }
}
